package m4;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName Producter
 * @Description:类描述
 * @Author Tedu
 * @Date 2021/6/29 9:37
 * @Version V1.0
 **/
public class Producter {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.连接
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Channel c = f.newConnection().createChannel();
        //2.创建direct交换机,direct_logs
        c.exchangeDeclare("direct_logs", BuiltinExchangeType.DIRECT);
        //3.发送消息
        while(true){
            System.out.println("输入消息: ");
           String s= new Scanner(System.in).nextLine();
           //自定义路由键
            System.out.println("输入路由键: ");
            String k= new Scanner(System.in).nextLine();
           //参数1,交换机  参数2路由键,默认交换机""的路由键就是队列名
           c.basicPublish("direct_logs", k,
                   null, s.getBytes());


        }

    }
}
